import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QLabel
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap

class OpenMultipleFilesDemo(QWidget):
    def __init__(self):
        super().__init__()
        self.init_ui()
        
    def init_ui(self):
        layout = QVBoxLayout()
        
        self.info_label = QLabel('选择的文件将显示在这里')
        self.info_label.setAlignment(Qt.AlignCenter)
        
        open_btn = QPushButton('打开多个文件')
        open_btn.clicked.connect(self.open_multiple_files)
        
        layout.addWidget(self.info_label)
        layout.addWidget(open_btn)
        self.setLayout(layout)
        self.setWindowTitle('多文件选择演示')
        
    def open_multiple_files(self):
        from PyQt5.QtWidgets import QFileDialog
        
        file_names, selected_filter = QFileDialog.getOpenFileNames(
            self,
            "选择多个文件",
            "",
            "图片文件 (*.png *.jpg *.jpeg *.bmp);;文本文件 (*.txt);;所有文件 (*)"
        )
        
        if file_names:
            file_list = "\n".join(file_names)
            self.info_label.setText(f"选择了 {len(file_names)} 个文件:\n{file_list}")
        else:
            self.info_label.setText("用户取消了选择")

            
if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = OpenMultipleFilesDemo()
    window.show()
    sys.exit(app.exec_())